﻿namespace _03.AnimalsExercise
{
    using System;
    using System.Linq;

    public abstract class Animal : ISound
    {
        private sbyte age;

        public string Name { get; set; }

        public Gender Sex { get; private set; }

        public Animal(sbyte age, string name, Gender sex)
        {
            this.Age = age;
            this.Name = name;
            this.Sex = sex;
        }

        public override string ToString()
        {
            return string.Format("Name: {0}, Sex: {1}, Age: {2}", this.Name, this.Sex, this.Age);
        }

        public sbyte Age
        {
            get
            {
                return this.age;
            }

            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("Age must be positive");
                }

                this.age = value;
            }
        }

        public abstract void ProduceSound();

        public static double Average(Animal[] animalArray)
        {
            return animalArray.Average(animal => animal.age);
        }
    }
}
